/**
 * Created by zander on 2018/1/10.
 */
/**
 * Created by zander on 2017/12/6.
 */

function getProject() {
    var a = document.getElementById("Project");
    var b = a.options[a.selectedIndex].value;
    return b;
}

function registrationIdentity() {
    var patrn1 = /^[0-9]*[1-9][0-9]*$/;  //只能输入数字
    var patrn = /^[0-9a-zA-Z]/;          //只能输入数字／字母a-z／字母A-Z
    var patrn2 = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$/; //只能输入字母和数组且最小位数位8位最大16
    var inputPhone = $('#inputPhone').val();
    var inputId = $('#inputID').val();
    var inputName = $('#inputName').val();
    var inputPwd = $('#inputPwd').val();
    var inputCard = $('#inputCard').val();
    if (inputPhone == "") {
        alert("手机号为空");
        return false;
    } else if (inputId == "") {
        alert("身份证号为空");
        return false;
    } else if (inputName == "") {
        alert("用户名不能为空");
        return false;
    } else if (inputPwd == "") {
        alert("密码不能为空");
        return false;
    } else if (inputCard == "") {
        alert("银行卡号不能为空");
        return false;
    } else if (!patrn1.test(inputPhone)) {
        alert("手机号只能输入数字");
        return false;
    } else if (!patrn.test(inputId)) {
        alert("身份证号格式不正确");
        return false;
    } else if (!patrn1.test(inputCard)) {
        alert("银行卡号只能输入数字");
        return false;
    }else if (!patrn2.test(inputPwd)){
        alert("密码不符合长度或者要求");
        return false;
    }
    document.getElementById('res').innerText = '';
    var project = getProject();
    var phone = document.getElementById('inputPhone').value;
    var password = document.getElementById('inputPwd').value;
    var identifier = document.getElementById('inputID').value;
    var realname = document.getElementById('inputName').value;
    var bankcard = document.getElementById('inputCard').value;
    sure(realname, project, phone, identifier, bankcard, password);
}
function sure(realname, project, phone, identifier, bankcard, password) {
    bootbox.confirm({
        size: "small",
        message: "是否确认执行?",
        callback: function (result) {
            if (result == true) {
                $.ajax({
                    type: "POST",
                    url: "/intest/v1/sign_validate",
                    data: {
                        phone: phone,
                        password: password,
                        realname: realname,
                        identifier: identifier,
                        project: project,
                        bankcard: bankcard
                    },
                    dataType: "json",
                    beforeSend:function(){
                        $("body").mLoading("show");
                    },
                    success: function (ret) {
                        if (ret.status == "0000") {
                            $("body").mLoading("hide");
                            $("#res").append(ret.message);
                        } else {
                            $("body").mLoading("hide");
                            $("#res").append(ret.message);
                        }
                    },
                    error: function() {
                        $("body").mLoading("hide");
                        $("#res").append("Error 500,请联系开发人员！");
                    }
                });

            }
        }
    })
}